<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MdiWin Demo - edit</title>
    <uieip type="file" value="inc" src="/yqwin/easyui/include.txt" cache="true" minute="1440"></uieip>
    <uieip type="file" value="css" src="/yqwin/css/yqwin.min" cache="false"></uieip>
    <uieip type="file" value="js" src="/yqwin/data/yqwin.min" cache="false"></uieip>
</head>

<body>
    <h2>yqTextTable</h2>
    <table id="tb" type="text" style="width:300px"></table>
    <p></p>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:setRows()">setRows</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:clearRun()">clear</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:getRows()">getRows</a>
    <input id="txt_width" value="280" style="width:120px;">
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:isEdit(true)">isEdit==true</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:isEdit(false)">isEdit==false</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:destroy()">destroy</a>

    <h2>yqTableEdit</h2>
    <table id="tb2" style="width:100%;height: 400px;">
    </table>
    <p></p>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:setRows2()">setRows</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:clearRows2()">clear</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:getRows2()">getRows</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:newLoad2()">newLoad</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:isEdit2(true)">isEdit==true</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:isEdit2(false)">isEdit==false</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:destroy2()">destroy</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:checkBoxRows2()">checkBoxRows</a>
    <p>---------------------------------------------------</p>
    <table id="tb_edit3" type="text" style="width:100%;height: 300px;"></table>
    <p></p>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:edit3_fun.isedit(true)">isEdit==true</a>
    <a href="#" class="easyui-linkbutton" data-options="" onclick="javascript:edit3_fun.isedit(false)">isEdit==false</a>
    <script>
        $(function () {
            $('#tb2').yqTableEdit({
                ajaxUrl: "",
                titles: titles,  //数据列配置对象
                rows: rows,
                //editModeW: 500, //模态编辑器宽度 格式为 800（数字）
                //editModeH: 180, //模态编辑器高度 格式为 600（数字）
                isEdit: true,
                isAdd: true,
                isDel: true,
                toexcel: true, //Excel导出
                excelName: "excel导出",   //Excel导出文件名
                inexcel: true, //Excel导入
                sumList: ["weight"],

                checkBoxCol: true,   //行选择复选框
                checkBoxFormatter: function (value, row, index) {  //选择渲染事件,true 渲染
                    return true;
                },
                checkBoxChecked: function (checkCount) {  //行选择事件 选择的数量
                    console.log("checkCount", checkCount);
                },
                checkBoxChange: function (row, checked) {
                    console.log("checkBoxChange", row, checked);
                },   //选择事件 行，是否选中

                beforBindingTitle: function (titles, callback) {
                    console.log("beforBindingTitle", titles);
                    callback(titles);
                }, //标题绑定前
                afterBindingTitle: function () {
                    console.log("afterBindingTitle");
                }, //标题绑定后       
                endEditing: function (index, row) {   //ok.....
                    console.log("endEditing", index, row);
                },
                beforeAdd: function (rows, row, callback) {
                    console.log("beforeAdd", rows, row);
                    callback(row);
                },
            });

            edit3_fun.load();

            $('#tb').yqTextTable({
                ajaxUrl: "",
                titles: titles,  //数据列配置对象
                rows: rows,
                isEdit: true,   //可编辑
                sumList: ["weight"],
                editModeW: 500, //模态编辑器宽度 格式为 800（数字）
                editModeH: 400, //模态编辑器高度 格式为 600（数字）
                beforBindingTitle: function (titles, callback) {
                    console.log("beforBindingTitle2", titles);
                    callback(titles);
                }, //标题绑定前
                afterBindingTitle: function () {
                    console.log("afterBindingTitle2");
                }, //标题绑定后       
                beforeAdd: function (rows, row, callback) {
                    console.log("beforeAdd2", rows, row);
                    callback(row);
                },
                afterChange: function (rows, callback) {
                    console.log("afterChange2", rows);
                },
            });

            $("#txt_width").numberspinner({
                min: 100,
                max: 1000,
                buttonText: "resize",
                onClickButton: function () {
                    $('#tb').yqTextTable("resize", $(this).numberspinner("getValue"));
                },
            })

            //$("#pp")
        })

        function setRows2() {
            $('#tb2').yqTableEdit("setRows", [{ "no": "1" }]);
        }
        function clearRows2() {
            $('#tb2').yqTableEdit("clear");
        }
        function getRows2() {
            var rows = $('#tb2').yqTableEdit("getRows");
            console.log("getRows", rows);
            console.log("getRows", JSON.stringify(rows, null, 2));
        }
        function newLoad2() {
            $('#tb2').yqTableEdit({
                titles: titles2,  //数据列配置对象
                rows: rows2,
            });
        }
        function isEdit2(tf) {
            $('#tb2').yqTableEdit("isEdit", tf);
        }
        function destroy2() {
            $('#tb2').yqTableEdit("destroy");
        }

        function checkBoxRows2() {
            var rows = $('#tb2').yqTableEdit("checkBoxRows");
            console.log(rows);
        }

        //-----------------------------
        function setRows() {
            $('#tb').yqTextTable("setRows", [{ "no": "1" }]);
        }
        function clearRun() {
            $('#tb').yqTextTable("clear");
        }
        function getRows() {
            console.log($('#tb').yqTextTable("getRows"));
        }
        function isEdit(tf) {
            $('#tb').yqTextTable("isEdit", tf);
        }
        function destroy() {
            $('#tb').yqTextTable("destroy");
        }

       

        var titles = [{
            "is_func": false,
            "name": "id",
            "ui_title": "id",
            "ui_type": 10,
            "ui_width": 40,
            "ui_visible": false,
            "ui_readonly": true,
            "ui_mask": {
                "blank": false,
                "min": 1,
                "groupSeparator": ""
            }
        }, {
            "is_func": false,
            "name": "uid",
            "ui_title": "uid",
            "ui_type": 2,
            "ui_width": 120,
            "ui_visible": true,
            "ui_readonly": true,
            "ui_mask": {
                "blank": false,
            }
        }, {
            "is_func": false,
            "name": "state",
            "ui_title": "项目阶段",
            "ui_type": 6,
            "ui_width": 130,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "default": 3,
                "lists": [
                    {
                        "no": "0",
                        "name": "草稿"
                    }, {
                        "no": "1",
                        "name": "项目策划阶段"
                    },
                    {
                        "no": "2",
                        "name": "项目可研阶段"
                    },
                    {
                        "no": "3",
                        "name": "项目实施阶段"
                    },
                    {
                        "no": "4",
                        "name": "项目竣工阶段"
                    },
                    {
                        "no": "5",
                        "name": "项目结项阶段"
                    }
                ]
            }
        }, {
            "is_func": false,
            "name": "title",
            "ui_title": "工作内容",
            "ui_type": 2,
            "ui_width": 130,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "blank": false,
            }
        }, {
            "is_func": false,
            "name": "describe",
            "ui_title": "描述",
            "ui_type": 5,
            "ui_width": 170,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "default": null,
                "editModeW": 400,
                "editModeH": 300,
            }
        }, {
            "is_func": false,
            "name": "workset",
            "ui_title": "工作设置",
            "ui_type": 6,
            "ui_width": 130,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "default": 3,
                "lists": [
                    {
                        "no": "3",
                        "name": "任务分解+流程"
                    },
                    {
                        "no": "2",
                        "name": "部门分解+流程"
                    },
                    {
                        "no": "1",
                        "name": "阶段流程"
                    }
                ]
            }
        }, {
            "is_func": false,
            "name": "weight",
            "ui_title": "产值权重",
            "ui_type": 9,
            "ui_width": 70,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "default": 0,
                "min": 0,
                "max": 100,
                "precision": 1,
                "groupSeparator": ""
            }
        }, {
            "is_func": false,
            "name": "wf",
            "ui_title": "流程设置",
            "ui_type": 15,
            "ui_width": 90,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "editModeW": 450,
                "editModeH": 240,
                "param": {
                    "titles": [{
                        "is_func": false,
                        "name": "type",
                        "ui_title": "项目类型",
                        "ui_type": 6,
                        "ui_width": 110,
                        "ui_visible": true,
                        "ui_readonly": false,
                        "ui_mask": {
                            "default": -1,
                            "lists": [
                                {
                                    "no": "1",
                                    "name": "小型项目"
                                },
                                {
                                    "no": "2",
                                    "name": "中型项目"
                                },
                                {
                                    "no": "3",
                                    "name": "重大项目"
                                }
                            ]
                        }
                    }, {
                        "is_func": false,
                        "name": "value",
                        "ui_title": "流程id",
                        "ui_type": 2,
                        "ui_width": 280,
                        "ui_visible": true,
                        "ui_readonly": false,
                        "ui_mask": {
                            "default": null,
                        }
                    }],
                    "model": []
                }
            }
        }, {
            "is_func": false,
            "name": "data",
            "ui_title": "数据设置",
            "ui_type": 16,
            "ui_width": 90,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "editModeW": 630,
                "editModeH": 400,
                "param": {
                    "titles": [
                        {
                            "is_func": false,
                            "name": "name",
                            "ui_title": "字段名称",
                            "ui_type": 2,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": null,
                            }
                        }, {
                            "is_func": false,
                            "name": "describe",
                            "ui_title": "描述",
                            "ui_type": 5,
                            "ui_width": 145,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": null,
                                "editModeW": 400,
                                "editModeH": 300
                            }
                        },
                        {
                            "is_func": false,
                            "name": "type",
                            "ui_title": "数据源",
                            "ui_type": 6,
                            "ui_width": 110,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": -1,
                                "lists": [
                                    {
                                        "no": "1",
                                        "name": "文件"
                                    },
                                    {
                                        "no": "2",
                                        "name": "报表"
                                    },
                                    {
                                        "no": "3",
                                        "name": "销售合同"
                                    },
                                    {
                                        "no": "4",
                                        "name": "采购合同"
                                    },
                                    {
                                        "no": "5",
                                        "name": "生产任务书"
                                    }
                                ]
                            }
                        },
                        {
                            "is_func": false,
                            "name": "attr",
                            "ui_title": "扩展参数",
                            "ui_type": 5,
                            "ui_width": 280,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {
                                "default": null
                            }
                        },
                        {
                            "is_func": false,
                            "name": "multi",
                            "ui_title": "多选",
                            "ui_type": 3,
                            "ui_width": 60,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {}
                        },
                        {
                            "is_func": false,
                            "name": "blank",
                            "ui_title": "允许为空",
                            "ui_type": 3,
                            "ui_width": 80,
                            "ui_visible": true,
                            "ui_readonly": false,
                            "ui_mask": {}
                        }
                    ],
                    "model": []
                }
            }
        },
        {
            "name": "foreignkey",
            "is_func": false,
            "ui_title": "ForeignKey",
            "fd_type": "nvarchar",
            "length": 36,
            "decimal": 0,
            "ui_type": 14,
            "ui_width": 180,
            "ui_visible": true,
            "ui_readonly": false,
            "ui_mask": {
                "default": null,
                "blank": true,
                "dbName": "yqbase",
                "tbName": "sys.sys_table",
                "tempNo": -1,
                "displayType": 1,
                "valueMember": "sid",
                "displayMember": "textbox",
                "isPage": true,
                "pageSize": 10,
                "addWhere": "",
                "order": "textbox",
                "panelWidth": 400,
                "panelHeight": 460,
                "expandMember": null,
                "seekNo": -1,
                "seekModeW": 800,
                "seekModeH": 600,
                "mapping": [
                    {
                        "from": "textbox",
                        "to": "foreignkeyVal"
                    }]
            }
        }, {
            "is_func": false,
            "name": "foreignkeyVal",
            "ui_title": "foreignkeyVal",
            "ui_type": 2,
            "ui_width": 140,
            "ui_visible": true,
            "ui_readonly": true,
            "ui_mask": {
            }
        }
        ];

        var rows = [
            {
                "id": 1,
                "uid": "uid12.0.1",
                "state": 0,
                "title": "项目策划审批",
                "workset": 1,
                "wf": [
                    {
                        "type": 2,
                        "value": "12312"
                    }
                ],
                "data": [
                    {
                        "name": "123",
                        "describe": "123123",
                        "type": 2,
                        "multi": false,
                        "blank": false
                    },
                    {
                        "name": "123",
                        "describe": "123123123",
                        "type": 2,
                        "attr": "123123",
                        "multi": false,
                        "blank": false
                    }
                ]
            },
            {
                "id": 2,
                "uid": "uid12.1.1",
                "state": 1,
                "title": "预可研",
                "describe": "项目策划描述",
                "workset": 3,
                "wf": [
                    {
                        "type": 1,
                        "value": "切尔奇"
                    }
                ]
            },
            {
                "id": 3,
                "uid": "uid12.1.2",
                "state": 2,
                "title": "项目可研审批",
                "workset": 1
            },
            {
                "id": 4,
                "uid": "uid12.2.1",
                "state": 2,
                "title": "可研阶段",
                "workset": 3
            },
            {
                "id": 5,
                "uid": "uid12.3.1",
                "state": 2,
                "title": "项目实施审批",
                "workset": 1
            },
            {
                "id": 6,
                "uid": "uid12.3.1",
                "state": 3,
                "title": "启动会",
                "workset": 1
            },
            {
                "id": 7,
                "uid": "uid12.3.2",
                "state": 3,
                "title": "需求分析阶段",
                "workset": 2,
                "weight": 20
            },
            {
                "id": 8,
                "uid": "uid12.3.3",
                "state": 3,
                "title": "系统设计阶段",
                "workset": 2,
                "weight": 20
            },
            {
                "id": 9,
                "uid": "uid12.3.4",
                "state": 3,
                "title": "软件编码",
                "workset": 2,
                "weight": 30
            },
            {
                "id": 10,
                "uid": "uid12.3.5",
                "state": 3,
                "title": "软件测试",
                "workset": 2,
                "weight": 10
            },
            {
                "id": 11,
                "uid": "uid12.3.6",
                "state": 3,
                "title": "中间检查",
                "workset": 2,
                "weight": 20
            },
            {
                "id": 12,
                "uid": "uid12.3.7",
                "state": 3,
                "title": "验收",
                "workset": 1
            },
            {
                "id": 13,
                "uid": "uid12.3.8",
                "state": 3,
                "title": "项目管理",
                "describe": "项目管理完成后=》项目竣工阶段",
                "workset": 1
            },
            {
                "id": 14,
                "uid": "uid12.4",
                "state": 4,
                "title": "竣工评审",
                "describe": "竣工评审后=》项目结算阶段",
                "workset": 3
            },
            {
                "id": 15,
                "uid": "uid12.5",
                "state": 5,
                "title": "结算评审",
                "describe": "结算评审=》项目进入完结状态",
                "workset": 3
            }
        ];

        var titles2 = [
            {
                "name": "no",
                "ui_title": "No",
                "ui_type": 2,
                "ui_width": 90,
                "ui_visible": true,
                "ui_readnnly": false,
                "ui_mask": {}
            }, {
                "name": "name",
                "ui_title": "Name",
                "ui_type": 2,
                "ui_width": 150,
                "ui_visible": true,
                "ui_readnnly": false,
                "ui_mask": {}
            }, {
                "name": "name2",
                "ui_title": "Name2",
                "ui_type": 2,
                "ui_width": 200,
                "ui_visible": true,
                "ui_readnnly": false,
                "ui_mask": {}
            }
        ];

        var rows2 = [
            { "no": "1", "name": "name1" },
            { "no": "2", "name": "name2" },
            { "no": "3", "name": "name3" }
        ];

        var edit3_fun = {
            id: "tb_edit3",
            titles: function () {
                var titles = [{
                    "name": "dept_id",
                    "ui_title": "部门",
                    "ui_type": 2,
                    "ui_width": 80,
                    "ui_visible": false,
                    "ui_readonly": true,
                    "ui_mask": {}
                }, {
                    "name": "dept_code",
                    "ui_title": "成本中心",
                    "ui_type": 2,
                    "ui_width": 80,
                    "ui_visible": false,
                    "ui_readonly": true,
                    "ui_mask": {}
                }, {
                    "name": "dept_name",
                    "ui_title": "部门名称",
                    "ui_type": 2,
                    "ui_width": 180,
                    "ui_visible": true,
                    "ui_readonly": true,
                    "ui_mask": {}
                }, {
                    "name": "type",
                    "ui_title": "指标",
                    "ui_type": 6,
                    "ui_width": 60,
                    "ui_visible": true,
                    "ui_readonly": true,
                    "ui_mask": {
                        "default": 1,
                        "lists": [
                            {
                                "no": "1",
                                "name": "合同额"
                            },
                            {
                                "no": "2",
                                "name": "产值"
                            },
                            {
                                "no": "3",
                                "name": "收入"
                            },
                            {
                                "no": "4",
                                "name": "收费"
                            }
                        ]
                    }
                }];

                var months = ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"];
                for (var i = 0; i < 12; i++) {
                    titles.push({
                        "name": "m" + (i + 1),
                        "ui_title": months[i] + "月",
                        "ui_type": 9,
                        "ui_width": 100,
                        "ui_visible": true,
                        "ui_readonly": false,
                        "ui_mask": {
                            "min": 0,
                            "precision": 2,
                            "groupSeparator": ","
                        }
                    });
                }

                titles.push({
                    "name": "ms",
                    "ui_title": "合计",
                    "ui_type": 9,
                    "ui_width": 100,
                    "ui_visible": true,
                    "ui_readonly": true,
                    "ui_mask": {
                        "min": 0,
                        "precision": 2,
                        "groupSeparator": ","
                    }
                });

                return titles;
            },
            rows: function () {
                var rows = [];
                for (var i = 0; i < 5; i++) {
                    for (var j = 0; j < 4; j++) {
                        var row = {
                            dept_id: "id" + (i + 1),
                            dept_code: "code" + (i + 1),
                            dept_name: "name" + (i + 1),
                            type: (j + 1)
                        }
                        var ms = 0;
                        for (var l = 0; l < 12; l++) {
                            row["m" + (l + 1)] = Math.random() * 4 + 1.5;
                            ms += row["m" + (l + 1)];
                        }
                        row["ms"] = ms;

                        rows.push(row);
                    }
                }

                return rows;
            },
            load: function () {
                $('#' + edit3_fun.id).yqTableEdit({
                    ajaxUrl: "",
                    titles: edit3_fun.titles(),  //数据列配置对象
                    rows: edit3_fun.rows(),
                    //editModeW: 500, //模态编辑器宽度 格式为 800（数字）
                    //editModeH: 180, //模态编辑器高度 格式为 600（数字）
                    isEdit: true,
                    isAdd: false,
                    isDel: false,
                    isMove: false,
                    toexcel: false,
                    excelName: "excel导出",
                    inexcel: false,
                    frozenNum: 2, //锁定列数量（锁定左侧）
                    sumList: ["m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "m10", "m11", "m12", "ms"],
                    beforBindingTitle: function (titles, callback) {
                        console.log("beforBindingTitle", titles);
                        callback(titles);
                    }, //标题绑定前
                    afterBindingTitle: function () {
                        console.log("afterBindingTitle");
                    }, //标题绑定后       
                    endEditing: function (index, row) {   //ok.....
                        console.log("endEditing", index, row);
                    },
                    beforeAdd: function (rows, row, callback) {
                        console.log("beforeAdd", rows, row);
                        callback(row);
                    },
                });
            },
            isedit: function (tf) {
                $('#' + edit3_fun.id).yqTableEdit("isEdit", tf);
            }

        }
    </script>
</body>

</html>